﻿@namespace BlazorFluentUI
@inherits FluentUIComponentBase
@typeparam TItem

<div @ref=@RootElementReference
     class="ms-ChoiceFieldGroup"
     style=@Style
     id="@Id"
     role="radiogroup"
     aria-labelledby=@($"{this.Id}_label")>
    @if (!string.IsNullOrWhiteSpace(this.Label))
    {
        <Label Id=@($"{this.Id}_label") Required=@Required>@this.Label</Label>
    }
    <div class=@($"ms-ChoiceFieldGroup-flexContainer{(this.ItemAlignment == FlexDirection.Row ? " flex-direction-row" : "")}")>
        <CascadingValue Value=this>
            @foreach (var item in this.ItemsSource!)
            {
                <ChoiceGroupOption Item="item"
                                      OptionTemplate="OptionTemplate"
                                      OnClick="OnChoiceOptionClicked"
                                      Required="Required"
                                      Focused=@(item!.Equals(focusedItem))
                                      OnFocus="OnFocus"
                                      OnBlur="OnBlur"
                                      />
            }
        </CascadingValue>
    </div>
</div>
